<template>
  <el-button text @click="table = true"> Open Drawer with nested table </el-button>
  <el-button text @click="dialog = true"> Open Drawer with nested form </el-button>
  <el-drawer
    v-model="table"
    title="I have a nested table inside!"
    direction="rtl"
    size="50%"
  >
    <el-table :data="gridData">
      <el-table-column property="date" label="Date" width="150" />
      <el-table-column property="name" label="Name" width="200" />
      <el-table-column property="address" label="Address" />
    </el-table>
  </el-drawer>

  <el-drawer
    ref="drawerRef"
    v-model="dialog"
    title="I have a nested form inside!"
    :before-close="handleClose"
    direction="ltr"
    class="demo-drawer"
  >
    <div class="demo-drawer__content">
      <el-form :model="form">
        <el-form-item label="Name" :label-width="formLabelWidth">
          <el-input v-model="form.name" autocomplete="off" />
        </el-form-item>
        <el-form-item label="Area" :label-width="formLabelWidth">
          <el-select v-model="form.region" placeholder="Please select activity area">
            <el-option label="Area1" value="shanghai" />
            <el-option label="Area2" value="beijing" />
          </el-select>
        </el-form-item>
      </el-form>
      <div class="demo-drawer__footer">
        <el-button @click="cancelForm">Cancel</el-button>
        <el-button type="primary" :loading="loading" @click="onClick">
          {{ loading ? 'Submitting ...' : 'Submit' }}
        </el-button>
      </div>
    </div>
  </el-drawer>
</template>
<script lang="ts">
import { defineComponent, ref, computed } from 'vue'
import { ElDrawer, ElMessageBox } from 'element-plus'
import { useStore } from 'vuex'
export default defineComponent({
    name: 'GDrawer',
    props: {
    // 按钮点击事件回调
        onSaveBtnClick: {
            type: Function,
            default: null
        },
        // 标题文字
        title: {
            type: String,
            default: ''
        },
        // 提交按钮文字
        saveBtnText: {
            type: String,
            default: '提 交'
        },
        // 是否显示返回按钮
        showBackBtn: {
            type: Boolean,
            default: true
        },
        // 是否显示按钮组
        showFooter: {
            type: Boolean,
            default: true
        }
    },
    setup(props) {
        const { state } = useStore()
        const isLoading = ref(false)

        const handleSaveClick = () => {
            if (props.onSaveBtnClick) {
                props.onSaveBtnClick((loading = true) => {
                    isLoading.value = loading
                })
            }
        }

        return {
            isLoading,
            isCollapse: computed(() => state.layout.isCollapse),
            handleSaveClick
        }
    }
})
</script>
<style lang="scss" scoped>
.g-form-wrap {
  &.show-footer {
    margin-bottom: 80px;
  }

  .el-card {
    box-shadow: 0 1px 12px 0 rgba(0, 0, 0, 0.05);
  }
}

.el-card {
  :deep(.el-card__header) {
    font-size: 16px;
    color: $primary;
    font-weight: 700;
  }
}

.form-btn-warp {
  width: 100%;
  padding: 20px;
  position: fixed;
  z-index: 4;
  bottom: 0;
  right: 0;
  background-color: #fff;
  left: 220px;
  transition: 0.3s ease-in-out;
  perspective: none;
  backface-visibility: hidden;
  box-shadow: 0 -2px 5px 0 rgba(0, 0, 0, 0.1);

  &.collapsed {
    left: 62px;
  }

  button {
    width: 100px;

    & + .el-button {
      margin-left: 15px;
    }
  }
}
</style>
